
  
//   @param {*} el 最大盒子
//   @param {*} option 其他参数设置
 
 function Swiper(el,option ={}) {
    this.el = document.querySelector(el);
    this.num = 1;
    this.t = null;
    this.init();
}

Swiper.prototype.init = function () {
    this.imgSwiper();
    this.fySwiper();
    this.changeObj();
}

Swiper.prototype.imgSwiper = function () {
    let oImg = this.el.querySelector('img');
    this.t = setInterval(() => {
        this.num++;
        if (this.num > 6) this.num = 1;
        oImg.src = `./img/b${this.num}.jpg`;
        // 分页器同步
        this.fySwiper();
    }, 1000)

    
}

Swiper.prototype.changeObj = function() {
    let oDots = this.el.querySelectorAll('ul li');
    let oImg = this.el.querySelector('img');
    oDots.forEach((item, i) => {
        item.onmouseover = () => {
            clearInterval(this.t);
            this.num = i + 1;
            // 图片地址同步
            oImg.src = `./img/b${this.num}.jpeg`;
            // 分页器同步
            this.fySwiper(this.num);
            item.onmouseout = () => {
                this.imgSwiper();
            }
        }
    });
}
// 同步分页器
Swiper.prototype.fySwiper = function () {
    
    this.el.querySelector('ul li.active').className = '';
    this.el.querySelectorAll('ul li')[this.num - 1].className = 'active';
}


export default Swiper;